package com.adgox.tiantianbiting.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.adgox.tiantianbiting.R;
import com.adgox.tiantianbiting.bean.RankIncomeBean;
import com.adgox.tiantianbiting.bean.RankListenBean;
import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by tang on 2019/2/25.
 */

public class RankingListenAdapter extends RecyclerView.Adapter<RankingListenAdapter.ViewHolder> {
    private List<RankListenBean> datas;

    public RankingListenAdapter(List<RankListenBean> datas) {
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_ranking_listen, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        RankListenBean bean = datas.get(position);
        if (position == 0) {
            holder.tvRank.setVisibility(View.GONE);
            holder.ivRank.setVisibility(View.VISIBLE);
            holder.ivRank.setImageResource(R.drawable.icon_rank1);
        } else if (position == 1) {
            holder.tvRank.setVisibility(View.GONE);
            holder.ivRank.setVisibility(View.VISIBLE);
            holder.ivRank.setImageResource(R.drawable.icon_rank2);
        } else if (position == 2) {
            holder.tvRank.setVisibility(View.GONE);
            holder.ivRank.setVisibility(View.VISIBLE);
            holder.ivRank.setImageResource(R.drawable.icon_rank3);
        } else {
            holder.ivRank.setVisibility(View.GONE);
            holder.tvRank.setVisibility(View.VISIBLE);
            holder.tvRank.setText((position + 1) + "");
        }

        if (bean.getImageUrl().isEmpty()) {
            holder.ivAvatar.setImageResource(R.drawable.ic_avatar);
        } else {
            Glide.with(holder.itemView.getContext()).load(bean.getImageUrl()).into(holder.ivAvatar);
        }
        holder.tvUsername.setText(bean.getWxNickname());
        holder.tvTime.setText((bean.getSumTime()/60) + "");

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_rank)
        ImageView ivRank;
        @BindView(R.id.tv_rank)
        TextView tvRank;
        @BindView(R.id.iv_avatar)
        RoundedImageView ivAvatar;
        @BindView(R.id.tv_username)
        TextView tvUsername;
        @BindView(R.id.tv_time)
        TextView tvTime;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
